package com.action;


import java.util.*;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.Interfacese.SearchByNameAndCode;
import com.actionForm.UserActionForm;
import com.biz.UserMessageHandle;
import com.factory.ProduceObject;

public class LoginAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession hs=request.getSession();
		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
		hs.setAttribute("cart",map);
		ProduceObject search = new ProduceObject();
		SearchByNameAndCode searchByNameAndCode = search.produceUserMessageHandle();
		UserActionForm loginForm = (UserActionForm)form;
		boolean b=searchByNameAndCode.searchByNameAndCode(loginForm.getUsername(), loginForm.getPassword());
		ActionForward af=null;
		if(b){
			HttpSession session = request.getSession(true);
			session.setAttribute("userName",loginForm.getUsername());
			af=mapping.findForward("success");
		}else af=mapping.findForward("eroor");
		return af;
		
	}

}
